/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bayu.services.dao;

import com.bayu.services.entity.TIncomingUsage;
import com.bayu.services.entity.TStock;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author submonkey
 */
@Repository("tIncomingUsageDao")
@Transactional
public class TIncomingUsageDao {
    public HibernateTemplate hibernateTemplate;

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        hibernateTemplate = new HibernateTemplate(sessionFactory);
    }

    @Transactional(readOnly=false)
    public void save(TIncomingUsage obj) {
        hibernateTemplate.saveOrUpdate(obj);
    }

    @Transactional(readOnly=false)
    public void delete(TIncomingUsage obj) {
        hibernateTemplate.delete(obj);
    }

    @Transactional(readOnly=false)
    public void update(TIncomingUsage obj) {
        hibernateTemplate.update(obj);
    }

    public List<TIncomingUsage> getAll(String query) {
        return hibernateTemplate.find(query);
    }

    public List<TIncomingUsage> getAllByDate(String start, String end) {
        return hibernateTemplate.find("from TIncomingUsage where tanggal between '"
            + start + "' and '" + end + "' order by tanggal asc)");
    }

    public List<TIncomingUsage> getById(int id) {
        return hibernateTemplate.find("from TIncomingUsage where id = " + id);
    }

    public List<TIncomingUsage> getAllByMonth(String month) {
        return hibernateTemplate.find("from TIncomingUsage where MONTH(tanggal)='" + month + "order by tanggal ASC" );
    }

    public List custom(String query) {
        return hibernateTemplate.find(query);
    }

    public double getMax() {
        return 0;
    }

    public double getMin() {
        return 0;
    }
}
